/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.edu.kamai.webservice;

import com.edu.kamai.config.Constant;
import com.edu.kamai.logic.facade.PaperAnswerFacade;
import com.edu.kamai.persistence.beans.PaperAnswer;
import java.util.Date;
import java.util.List;
import javax.jws.WebService;
import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.ejb.Stateless;

/**
 *
 * @author xyzhu
 */
@WebService(serviceName = "paperAnswerService")
@Stateless()
public class paperAnswerService {

    /**
     * Web 服务操作
     */
    @WebMethod(operationName = "addPaperAnswer")
    public Integer addPaperAnswer(@WebParam(name = "paperRole")
    int paperRole, @WebParam(name = "paperPath")
    String paperPath, @WebParam(name = "finshTime")
    int finshTime, @WebParam(name = "paperId")
    int paperId, @WebParam(name = "userId")
    String userId, @WebParam(name = "contestId")
    int contestId) {
        //TODO write your implementation code here:
        
        PaperAnswer pa = new PaperAnswer();
        pa.setContestId(contestId);
        pa.setUserId(userId);
        pa.setFinishTime(finshTime);
        pa.setPaperPath(paperPath);
        pa.setPaperRole(paperRole);
        pa.setPaperId(paperId);
        pa.setSubmitTime(new Date());
        pa.setPending(Constant.paperPending);
        pa.setScore(0);
        if(Constant.READING_PAPER_ID == paperRole){
            pa.setAutojudge(true);
        }else{
            pa.setAutojudge(false);
        }
        
        try{
            return PaperAnswerFacade.addPaperAnswer(pa);
        }catch(Exception ex){
            ex.printStackTrace();
        }
        
        return 0;
    }

    /**
     * Web 服务操作
     */
    @WebMethod(operationName = "getPendingAnswer")
    public List<PaperAnswer> getPendingAnswer() {
        //TODO write your implementation code here:
        return PaperAnswerFacade.chekPendingList();
    }

    /**
     * Web 服务操作
     */
    @WebMethod(operationName = "getAnswerPaper")
    public PaperAnswer getAnswerPaper(@WebParam(name = "aid")
    int aid) {
        //TODO write your implementation code here:
        return PaperAnswerFacade.getAnswerPaper(aid);
    }

    /**
     * Web 服务操作
     */
    @WebMethod(operationName = "updateScore")
    public int updateScore(@WebParam(name = "answerID")
    int answerID, @WebParam(name = "teacherName")
    String teacherName, @WebParam(name = "score")
    int score) {
        //TODO write your implementation code here:
        return PaperAnswerFacade.updatePaper(answerID, teacherName, score);
    }

    /**
     * Web 服务操作
     */
    @WebMethod(operationName = "getAnswerScoreByContestIDAndUserID")
    public List<PaperAnswer> getAnswerScoreByContestIDAndUserID(@WebParam(name = "ContestID")
    int ContestID, @WebParam(name = "UserID")
    String UserID) {
        //TODO write your implementation code here:
        return PaperAnswerFacade.getAnswerScoreByContestIDAndUserID
                (ContestID, UserID);
    }
}
